<template>
  <div class="countdown-card">
    <div class="countdown-header">
      <h2>考研倒计时</h2>
      <div class="countdown-icon">📅</div>
    </div>
    <div class="countdown-content">
      <div class="countdown-days">
        <span class="days-number">{{ remainingDays }}</span>
        <span class="days-label">天</span>
      </div>
      <div class="countdown-target">
        距离 {{ targetDate }} 还有
      </div>
    </div>
    <div class="progress-bar">
      <div class="progress-fill" :style="{ width: progress + '%' }"></div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

const targetDate = ref('2025-12-20')
const remainingDays = ref(0)
const progress = ref(0)

const calculateCountdown = () => {
  const target = new Date(targetDate.value)
  const today = new Date('2025-08-06') // 设置为2025年8月6日
  const diffTime = target - today
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
  
  remainingDays.value = diffDays > 0 ? diffDays : 0
  
  // 计算进度（从2025年1月1日开始）
  const startDate = new Date('2025-01-01')
  const totalDays = target - startDate
  const elapsedDays = today - startDate
  progress.value = Math.min((elapsedDays / totalDays) * 100, 100)
}

onMounted(() => {
  calculateCountdown()
  // 每天更新一次
  setInterval(calculateCountdown, 24 * 60 * 60 * 1000)
})
</script>

<style scoped>
.countdown-card {
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  border-radius: 20px;
  padding: 30px;
  color: white;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.countdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.countdown-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.countdown-icon {
  font-size: 30px;
}

.countdown-content {
  text-align: center;
  margin-bottom: 20px;
}

.countdown-days {
  margin-bottom: 10px;
}

.days-number {
  font-size: 48px;
  font-weight: bold;
  color: #64ffda;
  text-shadow: 0 0 20px rgba(100, 255, 218, 0.5);
}

.days-label {
  font-size: 24px;
  margin-left: 10px;
  color: rgba(255, 255, 255, 0.8);
}

.countdown-target {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.7);
}

.progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #64ffda, #00bcd4);
  transition: width 0.3s ease;
}
</style>